package com.zhengqing.app.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhengqing.app.config.custom.validator.UpdateGroup;
import com.zhengqing.app.model.dto.TestPageDTO;
import com.zhengqing.app.model.dto.TestSaveDTO;
import com.zhengqing.app.model.vo.ApiResult;
import com.zhengqing.app.model.vo.TestPageVO;
import com.zhengqing.app.service.ITestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p> 测试接口 </p>
 *
 * @author zhengqingya
 * @description
 * @date 2024/5/13 13:46
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/test")
@Api(tags = "测试api")
public class TestController {

    private final ITestService iTestService;

    @ApiOperation("分页")
    @GetMapping("/page")
    public ApiResult<IPage<TestPageVO>> page(@ModelAttribute TestPageDTO params) {
        return ApiResult.ok(this.iTestService.page(params));
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public Boolean add(@Validated @RequestBody TestSaveDTO params) {
        params.setId(null);
        this.iTestService.addOrUpdateData(params);
        return true;
    }

    @ApiOperation("更新")
    @PutMapping("/update")
    public Boolean update(@Validated(UpdateGroup.class) @RequestBody TestSaveDTO params) {
        this.iTestService.addOrUpdateData(params);
        return true;
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Boolean delete(@RequestParam Integer id) {
        this.iTestService.removeById(id);
        return true;
    }

}
